# 给定一个数字列表，请编写一个函数，找出其中长度最长的总和等于0的连续字串。数字允许出现正数和负数。
#
# 【示例】
# 输入：[1, 2, -3, 7, 8, -16]
# 输出：[1, 2, -3]
# 解释：连续相邻且总和为0的最长串就是1, 2, -3。
#
# 题目难度：中等
# 题目来源：CodeWars-Longest sequence with zero sum 4
def solution(nums: list) -> list:
    #遍历第一遍数组
    list1 = []
    for i in range(len(nums)):
        #遍历第二遍数组，从第一遍的下标+1开始
        for j in range(i+1,len(nums)+1):
            a = nums[i:j]
            #判断a是否=0，如果等于0 且比list1长，就赋值给list1
            if sum(a) == 0 and len(nums[i:j]) > len(list1):
                print(i,j)
                list1 = nums[i:j]
    print(list1)
    return list1

# def solution(nums: list) -> list:
#     result = []
#     l = len(nums)
#     for i in range(l):
#         for j in range(i + 1, l + 1):
#             data = nums[i:j]
#             if sum(data) == 0 and len(data) > len(result):
#                 print(i,j)
#                 result = data
#     return result

print(solution([1, 2, -3, 7, 8, -16]))
list1 = [1, 2, -3, 7, 8, -16]
print(list1[-1, 0])
# your code here

# assert solution([1, 2, -3, 7, 8, -16]) == [1, 2, -3]
# assert solution([25, -35, 12, 6, 92, -115, 17, 2, 2, 2, -7, 2, -9, 16, 2, -11]) == [92, -115, 17, 2, 2, 2]

# for i in range(10):
#     print(i)